class Solution {//leetcode494——目标和
private:
    void dfs(vector<int>&nums,int target,int pos){
        int n=nums.size();
        if(pos==n&&path==target){
            ret++;
            return;
        }
        if(pos==n) return;
        path+=nums[pos];
        dfs(nums,target,pos+1);
        path-=nums[pos];

        path-=nums[pos];
        dfs(nums,target,pos+1);
        path+=nums[pos];
        
    }
public:
    int findTargetSumWays(vector<int>& nums, int target) {
        dfs(nums,target,0);
        return ret;
    }
private:
    int path=0;
    int ret=0;
};//leetcode494——目标和